Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement SAR opcode #1134

Merged
merged 1 commit into from
Aug 7, 2018
Merged

Conversation

cburgdorf
Copy link
Contributor

@cburgdorf cburgdorf commented Aug 1, 2018

What was wrong?

This is a follow up to #1112 that also includes the SAR opcode. I branched this off because I feel less confident about this one compared to the other ones. That said, it passes all test cases that are specified in the EIP.

How was it fixed?

Implemented new opcode.

Cute Animal Picture

put a cute animal picture link inside the parentheses

value = unsigned_to_signed(value)

if shift_length >= 256:
result = 0 if value >= 0 else signed_to_unsigned(-1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we constantify signed_to_unsigned(-1)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense! However, I'm not sure if I got the naming right because my bits and bytes fu is pretty bad.

I added the following constant to eth.constants

UINT_255_NEGATIVE_ONE = -1 + UINT_256_CEILING

My understanding is that this is representing the number -1 according to the rules of the two's complement which uses the most significant bit to represent the sign and leaving us with 255 other bits to represent the number.

Btw, the constant basically inlines what signed_to_unsigned does because I can't import it here (circular import)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pipermerriam interpreted 👍 as indicator that the constant name seems reasonable and merged it

"""
Arithmetic bitwise right shift
"""
shift_length, value = computation.stack_pop(num_items=2, type_hint=constants.UINT256)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Side note, I just realized that we use keyword style calling for all stack operations, and a while back @davesque uncovered that calling things with positional arguments is significantly faster than keyword style calling. We should look into updating all of these call sites to use positional arguments.

@cburgdorf cburgdorf merged commit 2fac7ef into ethereum:master Aug 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants